<template>
  <div class="content">
    <div class="success_step">
      <p class="step">
        <span>付款成功（募集中）</span>
      </p>
      <p class="time">{{buy_list.dealTime}}</p>
    </div>

    <div class="nav">
      您有{{cont}}次翻牌福利
    </div>
    <div class="des">
      最高950元抵价券等您拿
    </div>
    <div class="card_content">
      <div class="item" v-for="(item,index) in cardlist" @click="selset(index)" :class="{'active':item.select}">
        <img src="../../public/imgs/buysuccess/card_default.png" alt="">
        <div class="item_sss">
          <div class="s_1">
            <span>￥</span>{{parseInt(item.money)}}
          </div>
          <div class="s_2">满{{parseInt(item.quota)}}元<br/> 可用</div>
          <div class="s_3">抵价券</div>
        </div>
      </div>
    </div>

    <mt-popup v-model="popupVisible" popup-transition="popup-slide" >
    </mt-popup>
    <div class="pouple animated" :class="{'zoomIn':popupVisible}" v-show="popupVisible">
      <div class="title">
        恭喜您获得首投抵价券
      </div>
       <div class="s_des">以上抵价券15天内有效，请及时使用</div>
      <div class="content">
        <div class="item_sss" v-for="item in selsetcrad">
          <div class="s_1">
            <span>￥</span>{{parseInt(item.money)}}
          </div>
          <div class="s_2">满{{parseInt(item.quota)}}元<br/> 可用</div>
          <div class="s_3">抵价券</div>
        </div>

      </div>
      <div class="btn" @click="jumpCom()">
        立即查收
      </div>
      <div class="close" @click="popupVisible=false">
        <img src="../../public/imgs/icon-close.png" alt="">
      </div>
    </div>
  </div>
</template>

<script>
import { Popup } from "mint-ui";
export default {
  props: [],
  data() {
    return {
      sessionid: "",
      buy_list: {},
      cardlist: [
        { money: "0", select: false },
        { money: "0", select: false },
        { money: "0", select: false },
        { money: "0", select: false },
        { money: "0", select: false },
        { money: "0", select: false }
      ],
      number: 0,
      cont:0,
      lock: true,
      popupVisible: false,
      selsetcrad:[],
    };
  },
  methods: {
    jumpCom(){
      this.Uitis.JumpNavite("jumpToCoupon","1")
    },
    init() {
      this.$http
        .get(this.Interface.getTopicPaySuccessFlopWeb, {
          params: { sessionid: this.sessionid }
        })
        .then(res => {
          if (res.data.success && res.data.data.list !== null) {
            for (var i = 0; i < res.data.data.list.length; i++) {
              res.data.data.list[i].select = false;
            }
            this.cardlist = res.data.data.list;
            this.cont = res.data.data.rewardSize;
          }
        });
    },
    selset(index) {
      if (this.cont > 0) {
        if (this.cardlist[index].select == true) {
          return false;
        }
        if (this.lock) {
          this.lock = false;
          this.$http
            .get(this.Interface.gettopic_pay_Success_flop_receive, {
              params: { sessionid: this.sessionid }
            })
            .then(res => {
              if (res.data.success) {
                if (res.data.data.money == this.cardlist[index].money) {
                  this.cardlist[index].money = res.data.data.money;
                  this.cardlist[index].quota = res.data.data.quota;
                  this.cardlist[index].select = true;
                  var oc={};
                  oc.money=res.data.data.money;
                  oc.quota=res.data.data.quota;
                  this.selsetcrad.push(oc)
                } else {
                  for (let i = 0; i < this.cardlist.length; i++) {
                    if (this.cardlist[i].money == res.data.data.money) {
                      var arr = this.cardlist[index];
                      this.cardlist[index] = this.cardlist[i];
                      this.cardlist[i] = arr;
                    }
                  }
                  this.cardlist[index].money = res.data.data.money;
                  this.cardlist[index].quota = res.data.data.quota;
                  this.cardlist[index].select = true;
                   var oc={};
                  oc.money=res.data.data.money;
                  oc.quota=res.data.data.quota;
                  this.selsetcrad.push(oc)
                }
                this.cont--;
                this.lock = true;
                if (this.cont <= 0) {
                  this.lock = false;
                  setTimeout(() => {
                    for (var i = 0; i < this.cardlist.length; i++) {
                      this.cardlist[i].select = true;
                    }
                  }, 1000);
                  setTimeout(() => {
                    this.popupVisible = true;
                  }, 2000);
                }
              }
            });
        }
      }
    }
  },

  created() {
    //我的投资详情
    this.Uitis.getInfo().then(data => {
      this.$http
        .get(this.Interface.getMyinvestDetail, {
          params: {
            partId: APP.GetLocationParams("partId"),
            sessionid: data.sessionid
          }
        })
        .then(res => {
          if (res.data.success == true) {
            this.buy_list = res.data.data;
          }
        });
    });
    this.Uitis.getInfo().then(res => {
      if (res.uId == "") {
        this.isLogin = false;
      } else {
        this.sessionid = res.sessionid;
        this.init();
      }
    });
  }
};
</script>


<style lang="less">

</style>
